library(survival)

# sdata <- dat

surv.obj <- Surv(time = sdata$value, event = sdata$event, type = "right")

surv.ana <- survfit(formula = surv.obj ~ sdata$id)
surv.ana
plot(surv.ana, lty = 1:2, lwd = 2)
legend(x = 15, y = 0.75, legend = c("Control", "Test"), lty = 1:2, cex = 0.75)

# ggsurvplot(surv.ana)

summary(surv.ana)

survdiff(surv.obj ~ sdata$id)

survdiff(surv.obj ~ sdata$id, rho = 1)

library(survminer)
ggsurvplot(surv.ana, data = sdata,
           title = "Survial Curves",
           pval = TRUE, pval.method = TRUE,          # Add p-value and method
           surv.median.line = "hv",                  # Add median survival lines
           legend.title = "Arm:",                    # Change legend titles
           legend.labs = c("Control", "Treatment"),  # Change legend labels
           palette = "jco",                          # Use JCO journal color palette
           risk.table = TRUE,                        # Add No at risk table
           cumevents = TRUE,                         # Add cumulative No of events table
           tables.height = 0.15,                     # Specify tables height
           tables.theme = theme_cleantable(),        # Clean theme for tables
           tables.y.text = FALSE                     # Hide tables y axis text
           )
